<?php

namespace DesignModel\ORM\model;

use DesignModel\database\mysqli;


/**
 * Created by PhpStorm.
 * User: 554665488
 * Date: 2018-6-20
 * Time: 9:48
 * @description: 数据库映射模式  ORM类 映射user表
 * @Author: yfl
 * @QQ 554665488
 */
class User
{
    public $id;
    public $name;
    protected $db;

    public function __construct($id=1)
    {
        $this->db = new mysqli();
        $this->db->connect('127.0.0.1', 'root', 'Abc123!Abc', 'test');
        $res = $this->db->query('select * from user where id = ' . $id . ' limit 1');
        $data = $res->fetch_assoc();
        $this->id = $data['id'];
        $this->name = $data['name'];
    }

    public function __destruct()
    {
        // TODO: Implement __destruct() method.

        $res=$this->db->query("update user set  name = '{$this->name}'  where id = $this->id limit 1");
//        echo "update user set  name = '{$this->name}'  where id = $this->id limit 1";echo '<br/>';
//        var_dump($res);
    }

}